package com.wwe.kotlinstudy.skill

import android.app.Activity
import android.os.Bundle
import java.io.File

//下面的是一些高级技巧，请慢慢体会
//这时候在block内，userInfo一直是非null的，run还顺手把上下文打开了
//如果你的代码出现大量的?.或者!!或者?:，那么你可以考虑用run、let等函数换种写法

/*
userInfo?.run {
    tvName.text = userName
    tvPhone.text = phone
    // ...
}*/

// Java
//UserInfo userInfo = gson.fromJson(jsonString, UserInfo.class);
// Kotlin
//val userInfo = gson.fromJson<UserInfo>(jsonString)

/*override fun onSaveInstanceState(outState: Bundle) {
    // Save the state so that next time we know if we need to refresh data.
    super.onSaveInstanceState(outState.apply {
        putBoolean(SHOULD_LOAD_DATA_FROM_REPO_KEY, addEditTaskPresenter.isDataMissing)
    })
}*/

/*// Set up the toolbar.
setupActionBar(R.id.toolbar) {
    setDisplayHomeAsUpEnabled(true)
    setDisplayShowHomeEnabled(true)
    setTitle(if (taskId == null) R.string.add_task else R.string.edit_task)
}*/

/*with(activity.findViewById<FloatingActionButton>(R.id.fab_edit_task_done)) {
    setImageResource(R.drawable.ic_done)
    setOnClickListener {
        presenter.saveTask(title.text.toString(), description.text.toString())
    }
}*/

/*
with(activity) {
    setResult(Activity.RESULT_OK)
    finish()
}
*/

/*
companion object {
    const val ARGUMENT_EDIT_TASK_ID = "EDIT_TASK_ID"

    fun newInstance(taskId: String?) =
            AddEditTaskFragment().apply {
                arguments = Bundle().apply {
                    putString(AddEditTaskFragment.ARGUMENT_EDIT_TASK_ID, taskId)
                }
            }
}
*/



fun makeDir(path: String): File {
    val result = File(path)
    result.mkdirs()
    return result
}

/** T.let返回的是作用域中的最后一个对象,它的值和类型都可以改变 */
/** 但是T.also不管调用多少次返回的都是原来的original对象 */
fun makeDir2(path: String) = path.let { File(it) }.also { it.mkdir() }

















